package com.pb.wkflow.api.controller.assembler.mapper;

import com.pb.infra.oth.util.UserInfo;
import com.pb.wkflow.api.controller.request.ProcessTaskRequest;
import com.pb.wkflow.api.query.CompleteTaskQuery;
import com.pb.wkflow.api.query.MyApplyTaskQuery;
import com.pb.wkflow.api.query.ProcInstanceQuery;
import com.pb.wkflow.api.query.TodoTaskQuery;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * DTO 转换
 * @author 苗益辉
 * @date 2022/12/27 8:51
 */
@Mapper
public interface ProcessTaskDtoMapper {

    ProcessTaskDtoMapper INSTANCE = Mappers.getMapper(ProcessTaskDtoMapper.class);

    /**
     * ProcInstanceQuery DTO 转换
     * @param request request
     * @return ProcInstanceQuery
     */
    @Mapping(target = "startTimeStart", source = "timeStr")
    @Mapping(target = "startTimeEnd", source = "timeEnd")
    ProcInstanceQuery assemblerToQuery(ProcessTaskRequest request);

    /**
     * MyApplyTaskQuery DTO 转换
     * @param request request
     * @param userInfo userInfo
     * @return MyApplyTaskQuery
     */
    @Mapping(target = "startUserId", source = "userInfo.userId")
    @Mapping(target = "procDefineKeyLike", source = "request.procDefineKeyLike")
    @Mapping(target = "procDefineNameLike", source = "request.procDefineNameLike")
    @Mapping(target = "startUserNameLike", source = "request.startUserNameLike")
    @Mapping(target = "startOrgNameLike", source = "request.startOrgNameLike")
    @Mapping(target = "tenantId", source = "userInfo.corpId")
    @Mapping(target = "startTimeStart", source = "request.timeStr")
    @Mapping(target = "startTimeEnd", source = "request.timeEnd")
    MyApplyTaskQuery assemblerToMyApplyQuery(ProcessTaskRequest request, UserInfo userInfo);

    /**
     * CompleteTaskQuery DTO 转换
     * @param request request
     * @param userInfo userInfo
     * @return CompleteTaskQuery
     */
    @Mapping(target = "taskId", source = "request.taskId")
    @Mapping(target = "userId", source = "userInfo.userId")
    @Mapping(target = "procDefineKeyLike", source = "request.procDefineKeyLike")
    @Mapping(target = "procDefineNameLike", source = "request.procDefineNameLike")
    @Mapping(target = "startUserNameLike", source = "request.startUserNameLike")
    @Mapping(target = "startOrgNameLike", source = "request.startOrgNameLike")
    @Mapping(target = "tenantId", source = "userInfo.corpId")
    @Mapping(target = "startTimeStart", source = "request.timeStr")
    @Mapping(target = "startTimeEnd", source = "request.timeEnd")
    CompleteTaskQuery assemblerToCompleteQuery(ProcessTaskRequest request, UserInfo userInfo);

    /**
     * TodoTaskQuery DTO 转换
     * @param request request
     * @param userInfo userInfo
     * @return TodoTaskQuery
     */
    @Mapping(target = "taskId", source = "request.taskId")
    @Mapping(target = "procDefineKeyLike", source = "request.procDefineKeyLike")
    @Mapping(target = "procDefineNameLike", source = "request.procDefineNameLike")
    @Mapping(target = "startUserNameLike", source = "request.startUserNameLike")
    @Mapping(target = "startOrgNameLike", source = "request.startOrgNameLike")
    @Mapping(target = "tenantId", source = "userInfo.corpId")
    @Mapping(target = "createTimeStart", source = "request.timeStr")
    @Mapping(target = "createTimeEnd", source = "request.timeEnd")
    TodoTaskQuery assemblerToTodoQuery(ProcessTaskRequest request, UserInfo userInfo);
}
